/*
* PROJECT: Happy New Year
* VERSION: 1.0
* AUTHOR: Mattias Thell
* URL: http://www.mattiasthell.com
*
* */

#pragma once

#include <vector>
#include <boost/shared_ptr.hpp>

#include "Actor.hpp"

namespace hny {

	#define HNY_ACTOR_DEFAULT_SIZE 20

	typedef boost::shared_ptr<Actor> ActorType;
	typedef std::vector<ActorType> ActorVector;

	class ActorManager
	{
	public:
		~ActorManager();

		static ActorManager* GetInstance();
		void Destroy();

		void Update(float dt);

		void CleanUp();

		void AddActor(ActorType actor);
		void FreeActor(int index);

		const ActorVector& GetActors();

		void EraseAll();

		unsigned int GetNewId();

	private:
		ActorManager();
		ActorManager(const ActorManager&);
		ActorManager& operator= (const ActorManager&);

		static ActorManager* mInstance;

		ActorVector mActors;
		ActorVector mNewActors;

		unsigned int mNextId;

		static const unsigned int ActorIdStart = 0;
		static const unsigned int ActorVectorDefaultSize = 20;
	};

	/* Helper predicate for std::erase(..) */
	class NeedsRemoval {
	public:
		bool operator() (const ActorType& a)  { return !a->IsAlive(); }
	};
}